package com.heima.service.impl;

import com.heima.mapper.ChannelMapper;
import com.heima.mapper.SkuClassMapper;
import com.heima.mapper.SkuMapper;
import com.heima.pojo.Channel;
import com.heima.pojo.Sku;
import com.heima.pojo.SkuClass;
import com.heima.pojo.dto.ChannelConfigDTO;
import com.heima.pojo.vo.SkuVo;
import com.heima.service.ChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChannelServiceImpl implements ChannelService {

    @Autowired
    private ChannelMapper channelMapper;
    @Autowired
    private SkuMapper skuMapper;
    @Autowired
    private SkuClassMapper skuClassMapper;

    @Override
    public List<Channel> channels(Integer innerCode) {
        List<Channel> channelList = channelMapper.channels(innerCode);
        List<SkuVo> skuVoList = skuMapper.queryAllSkuVo();
        List<SkuClass> skuClassList = skuClassMapper.queryAllSkuClass();
        for (Channel channel : channelList) {
            for (SkuVo skuVo : skuVoList) {
                for (SkuClass skuClass : skuClassList) {
                    if (skuClass.getClassId().equals(skuVo.getClassId())) {
                        skuVo.setSkuClass(skuClass);
                    }
                }
                if (skuVo.getSkuId().equals(channel.getSkuId())){
                    channel.setSkuVo(skuVo);
                }
            }
        }
        return channelList;
    }

    @Override
    public Boolean channelConfig(ChannelConfigDTO dto) {
        Integer result = channelMapper.channelConfig(dto);
        return result != 0;
    }




}
